#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e3 + 10;
int g[N][N];
int f[N][N];
int n, m;
int dfs(int x, int y)
{
	if (f[x][y] != -1)return f[x][y];
	if (x<0 || x>n || y<0 || y>m)return 0;
	if (y == m)return 0;
	if (g[x - 1][y + 1] > g[x][y])f[x][y] = dfs(x - 1, y + 1) + 1;// cout << "111" << endl;
	if (g[x][y + 1] > g[x][y])f[x][y] = dfs(x, y + 1) + 1;// cout << "222" << endl;
	if (g[x + 1][y + 1] > g[x][y])f[x][y] = dfs(x + 1, y + 1) + 1;// cout << "333" << endl;
	return f[x][y];
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> g[i][j];
		}
	}
	memset(f, -1, sizeof(f));
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		//cout << "i===" << i << "  dfs(1,i)==" << dfs(i, 1) << endl;
		ans = max(ans, dfs(i, 1));
	}
	cout << ans << endl;
	return 0;
}